package com.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.web.service.SysUserService;

@Controller
@RequestMapping("user")
public class SysUserController {

	@Autowired
	private SysUserService sysUserService;

	@ResponseBody
	@RequestMapping("doLogin")
	public Map<String, Object> doLogin(String userNum, String password, String keycode, HttpSession session,
			HttpServletRequest request) {
		System.out.println(userNum + " " + password);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		// 验证过程resultMap.put("result", "验证码错误");
		// String md5Password = DigestUtils.md5DigestAsHex(password.getBytes());
		String code = (String) session.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
		if (code.equals(keycode)) {
			resultMap = sysUserService.doLogin(userNum, password);
			//request.getSession().removeAttribute("captcha");
		} else {
			resultMap.put("result", -1);
		}
		return resultMap;
	}

}
